#include <cmath>
#include <vector>
using namespace std;

class Solution
{
public:
    static int sum(int n)
    {
        int sum = 0;
        while(n)
        {
            sum += pow(n%10, 2);
            n /= 10;
        }
        return sum;
    }

    static bool isHappy(int n)
    {
        int slow = n;
        int fast = sum(n);

        while(slow != fast)
        {
            slow = sum(slow);
            fast = sum(sum(fast));
        }

        return slow == 1;
    }
};
